<template>
    <Layout>
        <Form ref="form1" :model="form1" :label-width="120">
            <Row v-show="!switchFlag" class="query-form" style="padding-top: 15px">
                <Col span="8">
                    <FormItem label="库房名称：" prop="strageName">
                        <Input class="query-form-el" type="text" v-model="form1.strageName"></Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="物资名称：" prop="itemName">
                        <Input class="query-form-el" type="text" v-model="form1.itemName"></Input>
                    </FormItem>
                </Col>
                <Col span="8">

                    <Button @click="reset" class="ivu-btn-reset">重置</Button>
                    <Button type="primary" class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
                </Col>
            </Row>

            <Row class="query-form">
                <Col span="24">
                    <Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
                </Col>
            </Row>
        </Form>

        <Table ref='table' :height="tableHeight" :loading="loading" no-data-text="没有查询到相关数据!"
               @on-selection-change='getSelectRows'
               border :columns="columns1" :data="dataTable" size="small">
        </Table>
        <Row style="margin-right:10px;">
            <Col span="24">
                <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize"
                      @on-change="pageChange" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray"
                      show-total show-sizer show-elevator/>
            </Col>
        </Row>
        <Modal :title="add?'应急物资信息新增':'应急物资信息修改'" :transfer='false' v-model="model1" :width='600' @on-cancel="handleCancel">
            <Row>
                <Col span="24">
                    <Form ref="form1datacopy" :model="form1datacopy" :rules="ruleCustom" label-position="top">
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="7">
                                <FormItem label="库房：" prop="strageId">
                                    <Input type="text" readonly @on-focus="openSupplyModel"
                                           v-model="form1datacopy.esName"></Input>
                                    <Input type="text" v-show="false" v-model="form1datacopy.strageId"></Input>
                                </FormItem>
                            </Col>
                            <Col span="7">
                                <FormItem label="物资名称：" prop="itemName">
                                    <Input type="text" v-model="form1datacopy.itemName"></Input>
                                </FormItem>
                            </Col>
                            <Col span="7">
                                <FormItem label="生产厂商：" prop="vendor">
                                    <Input type="text" v-model="form1datacopy.vendor"></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="7">
                                <FormItem label="规格型号：" prop="itemModel">
                                    <Input type="text" v-model="form1datacopy.itemModel"></Input>
                                </FormItem>
                            </Col>
                            <Col span="7">
                                <FormItem label="生产日期（出厂日期）：" prop="proDate">
                                    <DatePicker v-model="form1datacopy.proDate" type="date"
                                                placeholder="请输入"></DatePicker>
                                </FormItem>
                            </Col>
                            <Col span="7">
                                <FormItem label="报废日期：" prop="retireDate">
                                    <DatePicker v-model="form1datacopy.retireDate" type="date"
                                                placeholder="请输入"></DatePicker>
                                </FormItem>
                            </Col>


                        </Row>

                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="7">
                                <FormItem label="物资分类：" prop="itemTypeId">
                                    <Select filterable v-model="form1datacopy.itemTypeId">
                                        <Option v-for="item in itemTypeList" :value="item.codingCodeId"
                                                :key="item.codingCodeId">{{ item.codingName }}
                                        </Option>
                                    </Select>
                                </FormItem>
                            </Col>
                            <Col span="7">
                                <FormItem label="归属单位：" prop="belongOrgId">
                                    <cascaderDom class="query-form-el" style="padding-top: 4px;width: 100%;" ref="carOrg"
                                                 @setOrgInfo="setStorageOrgId" @setOrgName="setStorageOrgName"
                                                 :currentOrgId="form1datacopy.belongOrgId"
                                                 :currentOrgName="form1datacopy.orgName" :orgTree="true"></cascaderDom>
                                </FormItem>
                            </Col>
                            <Col span="7">
                                <FormItem label="联系人：" prop="contractorId">
                                    <Select
                                            v-model="form1datacopy.contractorId"
                                            filterable
                                            :remote-method="remoteMethod1"
                                            :loading="loading1">
                                        <Option v-for="(option, index) in options1" :value="option.userId"
                                                :label="option.userName" :key="index">
                                            <span>{{option.userName}}</span>
                                            <span style="float:right;color:#ccc">{{option.orgInfo.orgName}}</span>
                                        </Option>
                                    </Select>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="7">
                                <FormItem label="联系电话：" prop="cellPhone">
                                    <Input type="text" v-model="form1datacopy.cellPhone"></Input>
                                </FormItem>
                            </Col>
                            <Col span="7">
                                <FormItem label="库存数量：" prop="quantity">
                                    <Input number v-model="form1datacopy.quantity"></Input>
                                </FormItem>
                            </Col>
                            <Col span="7">
                                <FormItem label="所属权性质：" prop="ownershipId">
                                    <Select filterable v-model="form1datacopy.ownershipId">
                                        <Option v-for="item in ownershipList" :value="item.codingCodeId"
                                                :key="item.codingCodeId">{{ item.codingName }}
                                        </Option>
                                    </Select>
                                </FormItem>
                            </Col>

                        </Row>

                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="7">
                                <FormItem label="计量单位：" prop="itemUnit">
                                    <Input type="text" v-model="form1datacopy.itemUnit"></Input>
                                </FormItem>
                            </Col>
                            <Col span="7">

                            </Col>
                            <Col span="7">

                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">

                            <Col span="23">
                                <FormItem label="用途描述：" prop="itemDesc">
                                    <Input v-model="form1datacopy.itemDesc" type="textarea" :rows="4"/>
                                </FormItem>
                            </Col>

                        </Row>
                        <!-- <Row type="flex" justify="center" class="code-row-bg">
                             <Col span="23" >
                                 <FormItem>
                                     <Button type="primary"  class='ivu-btn-save' :loading="buttonLoading" @click="submit('form1datacopy')" >确定</Button>
                                     <Button type="primary"  class='ivu-btn-cancel' @click="handleCancel" >取消</Button>
                                 </FormItem>
                             </Col>
                         </Row>-->
                    </Form>
                </Col>
            </Row>
            <div slot="footer">
                <Button type="primary" class='ivu-btn-save' :loading="buttonLoading" @click="submit('form1datacopy')">
                    确定
                </Button>
                <Button type="primary" class='ivu-btn-cancel' @click="handleCancel">取消</Button>
            </div>
        </Modal>
        <Modal title="应急物资信息详情" class="modal-view-detail" :transfer=false v-model="model2" :width=800>
            <Row>
                <Col span="24">
                    <Form :model="showdata" :label-width="160">
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="库房：" prop="esName">
                                    <a @click.prevent="getEsName">{{showdata.esName}}</a>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="物资名称：" prop="itemName">
                                    {{showdata.itemName}}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="生产厂商：" prop="vendor">
                                    {{showdata.vendor}}
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="规格型号：" prop="itemModel">
                                    {{showdata.itemModel}}
                                </FormItem>
                            </Col>

                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="生产日期：" prop="proDate">
                                    {{showdata.proDate}}
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="报废日期：" prop="retireDate">
                                    {{showdata.retireDate}}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="物资分类：" prop="itemTypeName">
                                    {{showdata.itemTypeName}}
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="归属单位：" prop="orgName">
                                    {{showdata.orgName}}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="联系人：" prop="userName">
                                    {{showdata.userName}}
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="库存数量：" prop="quantity">
                                    {{showdata.quantity}}
                                </FormItem>
                            </Col>

                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="所属权性质：" prop="ownershipName">
                                    {{showdata.ownershipName}}
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="计量单位：" prop="itemUnit">
                                    {{showdata.itemUnit}}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label="用途描述：" prop="itemDesc">
                                    {{showdata.itemDesc}}
                                </FormItem>
                            </Col>
                        </Row>
                    </Form>
                </Col>
            </Row>
            <div slot="footer">
                <Button type="primary" class='ivu-btn-save' @click="model2=false">确定</Button>
            </div>
        </Modal>
        <Modal title="应急库房信息" :transfer=false footer-hide v-model="storageForSelect" :width=900>
            <storageForSelect @getSelectData="getSelectData">
            </storageForSelect>
        </Modal>
        <Modal title="应急库房信息" class="modal-view-detail" :transfer=false v-model="showStorage" :width=800>
            <Row>
                <Col span="24">
                    <Form :model="strage" :label-width="160">
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="库房名称：" prop="esName">
                                    {{strage.esName}}
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="所属单位：" prop="belongOrgId">
                                    {{strage.orgName}}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="库房地址：" prop="esAddress">
                                    {{strage.esAddress}}
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="X坐标：" prop="axisX">
                                    {{strage.axisX}}
                                </FormItem>
                            </Col>

                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="Y坐标：" prop="axisY">
                                    {{strage.axisY}}
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="坐标名称：" prop="axisName ">
                                    {{strage.axisName }}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="联系人：" prop="userName ">
                                    {{strage.userName }}
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="联系电话：" prop="cellPhone">
                                    {{strage.cellPhone}}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="库房类型：" prop="esTypeName ">
                                    {{strage.esTypeName }}
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="库房级别：" prop="esLevelName ">
                                    {{strage.esLevelName }}
                                </FormItem>
                            </Col>
                        </Row>
                    </Form>
                </Col>
            </Row>
            <div slot="footer">
                <Button type="primary" class='ivu-btn-save' @click="showStorage=false">确定</Button>
            </div>
        </Modal>
    </Layout>
</template>

<script>
import {Api} from '../../../../api/index.js'
import cascaderDom from "../../../../components/cascader-dom.vue"
import storageForSelect from './storageForSelect.vue'
import {sessionStorage} from '../../../../common/cacheUtils.js';

export default {
        components: {
            cascaderDom,
            storageForSelect
        },
        data() {
            return {
                options1: [],
                setCurrentName: {},
                switchFlag: false,
                form1: {},
                pageSizeArray: [10, 20, 50],
                pagedata: {
                    total: 0,
                    pageSize: 10,
                    currentPage: 1,
                },
                dataTable: [],
                columns1: [
                    {
                        title: "序号",
                        width: 80,
                        align: "center",
                        fixed: 'left',
                        render: (h, params) => {
                            return h('span', params.index + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
                        }
                    },
                    {
                        title: '库房名称',
                        minWidth: 150,
                        align: 'center',
                        key: 'esName',
                    },
                    {
                        title: '物资名称',
                        minWidth: 150,
                        align: 'center',
                        key: 'itemName',
                    },
                    {
                        title: '生产厂商',
                        minWidth: 150,
                        align: 'center',
                        key: 'vendor',
                    },
                    {
                        title: '规格型号',
                        minWidth: 150,
                        align: 'center',
                        key: 'itemModel',
                    },
                    {
                        title: '生产日期（出厂日期）',
                        minWidth: 150,
                        align: 'center',
                        key: 'proDate',
                        render: (h, params) => {
                            return h('div', [
                                (this.formatDate(new Date(params.row.proDate), 'yyyy-MM-dd'))
                            ]);
                        }
                    },
                    {
                        title: '报废日期',
                        minWidth: 150,
                        align: 'center',
                        key: 'retireDate',
                        render: (h, params) => {
                            return h('div', [
                                (this.formatDate(new Date(params.row.retireDate), 'yyyy-MM-dd'))
                            ]);
                        }
                    },
                    {
                        title: '物资分类',
                        minWidth: 150,
                        align: 'center',
                        key: 'itemTypeName',
                    },
                    {
                        title: '联系人',
                        minWidth: 150,
                        align: 'center',
                        key: 'userName',
                    },
                    {
                        title: '联系电话',
                        minWidth: 150,
                        align: 'center',
                        key: 'cellPhone',
                    },
                    {
                        title: '操作',
                        key: 'action',
                        fixed: 'right',
                        width: 200,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px'
                                    },
                                    on: {
                                        click: () => {
                                            this.showData(params, 1);
                                        }
                                    }
                                }, '详情'),
                                h('Divider', {
                                    props: {
                                        type: 'vertical',
                                    }
                                }, ''),
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px',
                                    },
                                    on: {
                                        click: () => {
                                            this.showData(params, 2);
                                        }
                                    }
                                }, '修改'),
                                h('Divider', {
                                    props: {
                                        type: 'vertical',
                                    }
                                }, ''),
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px',
                                        color: 'red'
                                    },
                                    on: {
                                        click: () => {

                                            this.$Modal.confirm({
                                                title: '数据删除',
                                                content: '<p>确定删除该条信息</p>',
                                                okText: '确认',
                                                onOk: () => {
                                                    this.deleteData(params);
                                                },
                                                cancelText: '取消'
                                            });

                                        }
                                    }
                                }, '删除'),
                            ]);
                        }
                    },

                ],
                ruleCustom: {
                    strageId: [
                        {required: true, message: '  ', trigger: 'change'}
                    ],
                    itemName: [
                        {required: true, message: '  ', trigger: 'blur'}
                    ],

                },
                strage: {},
                add: false,
                showStorage: false,
                model1: false,
                buttonLoading: false, model2: false,
                storageForSelect: false,
                showdata: {},
                form1datacopy: {},
                itemTypeList: [],
                ownershipList: [],
                tableHeight: 10, loading: false,
                currentOrgId: '',
                currentOrgName: '',
                loading1:false,
            }
        },
        mounted() {
            this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 145;
            this.selectCodingSort();
            this.query();
        },
        methods: {
            getEsName() {
                this.showStorage = true;
            },
            setUserName(data) {
                this.form1datacopy.userName = data;
            },
            setUserId(data) {
                this.form1datacopy.contractorId = data[data.length - 1];
            },
            openSupplyModel() {
                this.storageForSelect = true;
            },
            getSelectData(row) {
                this.form1datacopy.strageId = row.esId;
                this.form1datacopy.esName = row.esName;
                this.storageForSelect = false;
            },
            deleteData(params) {
                let url = Api.deleteEmergencyStorageItem;
                this.$http.delete(url + '/' + params.row.itemId, {params: {}}).then((res) => {
                    if (res.data.status === 200) {
                        this.$Message.success('成功');
                        this.query()
                    } else if (res.data.status === 201) {
                        this.$Message.error(res.data.msg);

                    }
                }).catch(e => {
                    this.$Message.error('请求失败' + e);
                })
            },
            setStorageOrgId(data) {
                this.form1datacopy.belongOrgId = data[data.length - 1];
            },
            setStorageOrgName(data) {
                this.form1datacopy.orgName = data;
            },
            setOrgId(data) {
                this.form1.belongOrgId = data[data.length - 1];
            },
            setOrgName(data) {
                this.form1.orgName = data;
            },
            remoteMethod1(query) {
                if (query !== '') {
                    clearTimeout(this.remoteMethod1.timer);
					// if(query == this.form1datacopy.contactorId){
					// 	query = this.form1datacopy.userName;
					// }
					if(this.form1datacopy.userName != undefined || this.form1datacopy.userName != null){
						query = this.form1datacopy.userName;
					}
                    this.remoteMethod1.timer = setTimeout(() => {
                        this.options1.splice(0, this.options1.length);
                        this.loading1 = true;
                        let data = {
                            userName: query,
                            orgId: sessionStorage('userId').getObject('userId').orgInfo.parentId
                        };
                        this.$http.get(Api.queryUserByUserName, {params: data}).then((res) => {
                            this.loading1 = false;
                            res.data.data.forEach(item => {
                                this.options1.push(item);
                            })

                        }).catch(e => {
                            this.loading1 = false;
                        })
                    }, 200);
                } else {
                    this.options1 = [];
                }
            },
            getSelectRows(rows) {
                this.deleteRows = rows;
            },
            batDelete() {

            },
            addInfo() {
                this.options1.push({
                    userId: sessionStorage('userId').getObject('userId').userId,
                    userName: sessionStorage('userId').getObject('userId').userName,
                    orgInfo: {orgName:sessionStorage('userId').getObject('userId').orgInfo.orgName,}
                });
                this.form1datacopy = {
                    contractorId:sessionStorage('userId').getObject('userId').userId,
                    belongOrgId:sessionStorage('userId').getObject('userId').companyId,
                    orgName:sessionStorage('userId').getObject('userId').companyName,
                };
                this.setCurrentName = {};
                this.currentOrgId = '';
                this.currentOrgName = '';
                this.model1 = true;
                this.add = true;
            },
            pageChange(pageNum) {
                this.pagedata.currentPage = pageNum;
                this.query();
            },
            pageSizeChange(pageSize) {
                this.pagedata.pageSize = pageSize;
                this.query();
            },
            handleCancel() {
                this.form1datacopy = {};
				this.options1 = [];
                this.model1 = false;
            },
            selectCodingSort() {
                this.$http.get(Api.queryCodeDetailBySortId + '/MC-000001', {params: {}}).then((res) => {
                    this.itemTypeList = res.data.data;
                });
                this.$http.get(Api.queryCodeDetailBySortId + '/NOO-000001', {params: {}}).then((res) => {
                    this.ownershipList = res.data.data;
                });

            },
            switchQuery(flag) {
                this.switchFlag = flag;
                if (!this.switchFlag) {
                    this.tableHeight = window.innerHeight - 220;
                } else {
                    this.tableHeight = window.innerHeight - 315;
                }
            },
            reset() {
                this.form1 = {}
            },
            query() {
                this.loading = true;
                let data = {
                    startPage: this.pagedata.currentPage,
                    size: this.pagedata.pageSize,
                    orgId: sessionStorage('userId').getObject('userId').companyId,
                    type:this.$route.query.id
                };
                data = Object.assign(data, JSON.parse(JSON.stringify(this.form1)));

                let url = Api.queryEmergencyStorageItem;
                this.$http.get(url, {params: data}).then((res) => {
                    this.dataTable = res.data.data.data;
                    this.pagedata.total = res.data.data.totalSize;
                    this.loading = false;
                }).catch(e => {
                    this.$Message.error("数据获取失败")
                })
            },
            showData(data, flag) {
                this.currentOrgId = data.row.belongOrgId;
                this.currentOrgName = data.row.orgName;

                if (flag == 1) {
                    //查看页面
					this.options1 = [];
                    this.showdata = data.row;
                    this.showdata.proDate = this.formatDate(new Date(this.showdata.proDate), 'yyyy-MM-dd');
                    this.showdata.retireDate = this.formatDate(new Date(this.showdata.retireDate), 'yyyy-MM-dd');
                    this.model2 = true;
                    this.$http.get(Api.getEmergencyStorage + "/" + this.showdata.strageId).then((res) => {
                        this.strage = res.data.data;
                    }).catch(e => {
                        this.query();
                        this.$Message.error("数据获取失败")
                    })
                } else {
                    //修改页面
                    this.add = false;
                    this.form1datacopy = JSON.parse(JSON.stringify(data.row));
                    this.setCurrentName = {value: data.row.contractorId, label: data.row.userName};

                    this.model1 = true;
                }
            },
			formatDate(date, fmt) {
                if (/(y+)/.test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
                }
                let o = {
                    'M+': date.getMonth() + 1,
                    'd+': date.getDate(),
                    'h+': date.getHours(),
                    'm+': date.getMinutes(),
                    's+': date.getSeconds()
                };
                for (let k in o) {
                    if (new RegExp(`(${k})`).test(fmt)) {
                        let str = o[k] + '';
                        fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
                    }
                }
                return fmt;
            },
            submit(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        let userId = sessionStorage('userId').getObject('userId').userId;
                        let orgId = sessionStorage('userId').getObject('userId').orgInfo.orgId;
                        this.buttonLoading = true
                        if (this.form1datacopy.proDate != undefined){
                            this.form1datacopy.proDate = this.formatDate(new Date(this.form1datacopy.proDate), 'yyyy-MM-dd');
                        }
                        if (this.form1datacopy.retireDate != undefined) {
                            this.form1datacopy.retireDate = this.formatDate(new Date(this.form1datacopy.retireDate), 'yyyy-MM-dd');
                        }
                        this.form1datacopy.emeType =  this.$route.query.id;
                        console.log(this.form1datacopy);
                        if (this.add) {
                            this.form1datacopy.createUserId = userId;
                            this.form1datacopy.createOrgId = orgId;
                            this.$http.post(Api.saveEmergencyStorageItem, this.form1datacopy).then((res) => {
                                if (res.data.status === 200) {
                                    this.$Message.success('成功');
                                    this.model1 = false;
                                    this.query()

                                } else if (res.data.status === 201) {
                                    this.$Message.error(res.data.msg);
                                    this.model1 = false;
                                }
								this.form1datacopy = {};
								this.options1 = [];
                                this.buttonLoading = false
                            }).catch(e => {
                                this.model1 = false;
								this.form1datacopy = {};
								this.options1 = [];
                                this.query();
                                this.buttonLoading = false
                                this.$Message.error("数据获取失败")
                            })
                        } else {
                            this.form1datacopy.updateUserId = userId;
                            this.form1datacopy.updateOrgId = orgId;
                            this.$http.post(Api.updateEmergencyStorageItem, this.form1datacopy).then((res) => {
                                if (res.data.status === 200) {
                                    this.$Message.success('成功');
                                    this.model1 = false;
                                    this.query()

                                } else if (res.data.status === 201) {
                                    this.$Message.error(res.data.msg);
                                    this.model1 = false;
                                }
								this.form1datacopy = {};
								this.options1 = [];
                                this.buttonLoading = false
                            }).catch(e => {
                                this.model1 = false;
								this.form1datacopy = {};
								this.options1 = [];
                                this.query();
                                this.buttonLoading = false
                                this.$Message.error("数据获取失败")
                            })
                        }
                    } else {
                        this.$Message.error('请填报完整!');
                    }
                })
            },
            padLeftZero(str) {
                return ('00' + str).substr(str.length);
            },

        },
        watch: {
            "model1": function (qw, er) {
                if (qw && this.model1) {
                    setTimeout(() => {
                        this.$refs.carOrg.setCurrentOrg();
                    }, 100)
                } else {
                    this.$refs.carOrg.resetCurrentOrg();
                }
            },
        },

    }
</script>

<style lang='css' scoped>
    @import '../../../../index.css';
</style>
